#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <stdlib.h>
#include <sys/wait.h>

int main()
{
    pid_t id = fork();
    if (id == 0)
    {
        //int cnt = 5;
        while (1)
        {
            printf("我是子进程, pid:%d\n", getpid());
            sleep(1);
        }
        exit(1);
    }
    else if (id > 0)
    {
        int status = 0;
        sleep(10);
        pid_t rid = waitpid(id, &status, 0);
        printf("我是父进程, pid:%d\n", getpid());

        if (rid == id)
        {
            int exit_code = ((status >> 8) & 0xFF);
            int exit_sig = (status & 0x7F);
            printf("wait success!, status:%d, exit_code:%d, exit_sig:%d\n", status, exit_code, exit_sig);
        };
    }


}


//void Print()
//{
//    printf("I am a process, pid:%d", getpid());
//    sleep(5);
//    //_exit(123);
//    exit(123);
//}
//
//int main()
//{
//    Print(); 
//}
